package com.alphawavesgames.engine.utilities;

/**
 *
 * @author Andrew Dyer
 */
public class Dice {

    /**
     * Simulates rolling a die with the given number of sides. E.g. rolling a
     * d6.
     * 
     * @param sides The number of sides on the die.
     * @return The rolled number.
     */
    public static int rollDX(int sides) {
        return (int)(Math.random() * sides) + 1;
    }

    /**
     * Simulates rolling a given number of dice of the given amount of sides.
     * E.g. rolling 2d6.
     *
     * @param numOfDice The number of dice being rolled.
     * @param sides The number of sides of each die.
     * @return The total value of all the rolled dice.
     */
    public static int rollXDY(int numOfDice, int sides) {
        int total = 0;

        for(int i = 0; i < numOfDice; i++) {
            total += rollDX(sides);
        }

        return total;
    }

    /**
     * Simulates the multiplying of a roll with a constant by a given amount.
     * E.g. 2d6 + 3 times by 2 = 4d6 + 6.
     *
     * @param numOfDice How many dice being rolled.
     * @param sides The number of sides of each die.
     * @param constant The added constant to the die rolls.
     * @param multiplier The multiplier of the entire roll.
     * @return The total value of all the rolls and constants multiplied by a
     * given factor.
     */
    public static int multiplyRollXDYPlusZByN(int numOfDice, int sides, int constant, int multiplier) {
        int total = 0;

        for(int i = 0; i < multiplier; i++) {
            total += rollXDY(numOfDice, sides) + constant;
        }

        return total;
    }
}
